package org.swingDemo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class SimpleDateFormatDemo {

    public static void displayDate(Locale locale) {
        Date today;
        String result;
        SimpleDateFormat formatter;

        formatter = new SimpleDateFormat("EEE d MMM yy", locale);
        today = new Date();
        result = formatter.format(today);

        System.out.println("Locale: " + locale);
        System.out.println("Result: " + result);
    }

    public static void displayPattern(String pattern, Locale locale) {
        Date today;
        String result;
        SimpleDateFormat formatter;

        formatter = new SimpleDateFormat(pattern, locale);
        today = new Date();
        result = formatter.format(today);

        System.out.println(pattern + "  " + result);
    }

    public static void main(String[] args) {
        Locale[] locales = {
                new Locale("zh", "CN"),
                new Locale("en", "US")
        };

        for (Locale locale : locales) {
            displayDate(locale);
            System.out.println();
        }

        String[] patterns = {
                "dd.MM.yy",
                "yyyy.MM.dd G 'at' hh:mm:ss z",
                "EEE, MMM d, ''yy",
                "h:mm a",
                "H:mm",
                "H:mm:ss:SSS",
                "K:mm a,z",
                "yyyy.MMMMM.dd GGG hh:mm aaa"
        };

        for (String pattern : patterns) {
            displayPattern(pattern, new Locale("zh", "CN"));
            System.out.println();
        }
    }
}
